﻿create PROCEDURE Sync.SP_Users_SelectChanges
@LastRowVersion rowversion,
@FilterdColumn UNIQUEIDENTIFIER
AS 
BEGIN 
	SELECT 
        t.[UserID],
		g.[Username],g.[Password],g.[DisplayName],g.[Birthdate],g.[JobTitle],g.[Email],
		t.IsDeleted,
		t.LastUpdatedDate
	FROM [dbo].[Users] g RIGHT JOIN Sync.Users_Tracking t  
    ON t.UserID = g.UserID 
    join [UsersCommittees] comms
		on g.UserID = comms.UserID
	WHERE (@LastRowVersion IS NULL OR t.Version > @LastRowVersion)
		AND ((@FilterdColumn IS NULL) OR (@FilterdColumn = comms.CommitteeID))
    END














